package com.example.administrator.shzs.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.example.administrator.shzs.R;
import com.example.administrator.shzs.activity.BaseActivity;
import com.example.administrator.shzs.app.MyApplication;
import com.example.administrator.shzs.url.Contents;
import com.example.administrator.shzs.entity.SubmitEvaluate;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.LinkedHashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 订单评价
 */
public class OrderEvaluate extends BaseActivity implements View.OnClickListener {


    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.Sumbit)
    TextView Sumbit;
    @Bind(R.id.DeliveryTitle)
    RelativeLayout DeliveryTitle;
    @Bind(R.id.DeliveryImage)
    CircleImageView DeliveryImage;
    @Bind(R.id.DeliveryName)
    TextView DeliveryName;
    @Bind(R.id.DeliveryEvaluate)
    RatingBar DeliveryEvaluate;
    @Bind(R.id.Delivery)
    LinearLayout Delivery;
    @Bind(R.id.ShopMerchantImage)
    CircleImageView ShopMerchantImage;
    @Bind(R.id.ShopMerchantName)
    TextView ShopMerchantName;
    @Bind(R.id.ShopMerchantNameEvaluate)
    RatingBar ShopMerchantNameEvaluate;
    @Bind(R.id.ordermodel)
    EditText ordermodel;
    @Bind(R.id.ShopMerchant)
    LinearLayout ShopMerchant;
    @Bind(R.id.activity_order_evaluate)
    RelativeLayout activityOrderEvaluate;

    private SubmitEvaluate data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_evaluate);
        ButterKnife.bind(this);
        MyApplication.app.activityList.add(this);

        setData();
        iniEvent();

    }

    private void setData() {
        Intent intent = new Intent();


    }

    private void iniEvent() {
        Sumbit.setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                onBackPressed();
                break;
            case R.id.Sumbit:
                //请求网络
                iniDataFromWeb();
                break;
        }
    }

    //
    private void iniDataFromWeb() {

        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        map.put("point", "5");
        map.put("Comment", "服务很好，以后就用咱们生活了");
        map.put("FlavorGrade", "5");
        map.put("UserID", "50");
        map.put("UserName", "50");
        map.put("SpeedGrade", "5");
        map.put("orderid", "16090210174794730");
        map.put("foodname", "");
        map.put("TogoID", "984");
        map.put("ServiceGrade", "5");
        Gson gson = new Gson();
        String json = gson.toJson(map);

        RequestBody params = new FormBody.Builder().
                add("ordermodel", "{" + json + "}").build();


        String url = Contents.SUBMIT_EVALUATE;

        Request request = new Request.Builder().url(url).post(params).build();

        Contents.okhttp.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                String s = response.body().string();
                data = JSON.parseObject(s, SubmitEvaluate.class);
                int state = data.getState();

                if (state == 1) {
                    Toast.makeText(OrderEvaluate.this, "提交评论成功", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(OrderEvaluate.this, "提交评论异常", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }
}
